
<input type="file" id="imgfile" onchange="onInputChange()" method="post" enctype="multipart/form-data">
<button type="button" onclick="ToBase64();">转换</button>
<div>
    <textarea rows="10" cols="60" id="result"></textarea>
</div>


<script>


function onInputChange(e) {
    console.log('>> onInputChange')
    ToBase64()
}

function ToBase64() {
 
    /*转换base64*/
    var img = document.getElementById('imgfile')
    var imgFile = new FileReader();
    imgFile.readAsDataURL(img.files[0]);

    imgFile.onload = function () {
        var imgData = this.result; //base64数据  
        console.log(imgData);
        el = document.getElementById('result')
        el.value = imgData
    }

}



</script>